/*
    网络版通讯录
*/
#include "contacts_client.hpp"

void menu() {
    std::cout << "-----------------------------------------------------" << std::endl;
    std::cout << "---------------- 请选择对通讯录的操作 -----------------" << std::endl;
    std::cout << "------------------ 1. 新增联系人     -----------------" << std::endl; 
    std::cout << "------------------ 2. 删除联系人     -----------------" << std::endl;
    std::cout << "------------------ 3. 查看联系人     -----------------" << std::endl;
    std::cout << "------------------ 4. 查看联系人列表  ----------------" << std::endl;
    std::cout << "------------------ 0. 退出           ----------------" << std::endl;
    std::cout << "-----------------------------------------------------" << std::endl;
}

enum class OPERATE
{
    EXIT = 0,
    ADD,
    DELETE,
    QUERY,
    QUERYLIST,
};

int main()
{
    std::shared_ptr<httplib::Client> client_ptr = std::make_shared<httplib::Client>("127.0.0.1", 8080);
    ContactsClient client(client_ptr);
    while(true)
    {
        menu();
        std::cout << "---> 请选择: ";
        int choice; 
        std::cin >> choice;
        std::cin.ignore(256, '\n');
        switch(static_cast<OPERATE>(choice))
        {
        case OPERATE::ADD:
            client.AddContacts();
            break;
        case OPERATE::DELETE:
            client.DeleteContacts();
            break;
        case OPERATE::QUERY:
            client.QueryContacts();
            break;
        case OPERATE::QUERYLIST:
            client.QueryContactsList();
            break;
        case OPERATE::EXIT:
            std::cout << "---> 退出程序" << std::endl;
            return 0;
        default:
            std::cout << "---> 输入错误, 请重新输入" << std::endl;
            break;
        }
    };
    return 0;
}